package net.gz01.wallet.web.controller.merch;



import net.gz01.util.ZOMD5;
import net.gz01.wallet.web.controller.BaseController;
import net.gz01.wallet.web.model.MerchUser;

public class MerchUserController extends BaseController{

	public void index(){
		setAttr("sidebar", getSession().getAttribute("sidebar"));
		render("index.html");
	}

	public void verinfo(){
		render("index.html");
	}

	public void changePasswordPage(){
		render("changePassword.html");
	}

	public void changePassword(){
		String userId = getPara("userId");
		String oldPassword = getPara("oldPassword");
		String newPassword = getPara("newPassword");
		MerchUser user = MerchUser.dao.findById(userId);
		if(user.getPassword().equalsIgnoreCase(ZOMD5.codeFor(oldPassword))){
			user.setPassword(ZOMD5.codeFor(newPassword));
			user.update();
			renderSuccess("修改登录密码成功.");
		}else{
			renderFail("旧登录密码错误.");
		}
	}


	public void changePayPassword(){
		String userId = getPara("userId");
		String oldPassword = getPara("oldPayPassword");
		String newPassword = getPara("newPayPassword");
		MerchUser user = MerchUser.dao.findById(userId);
		if (user.getPayPassword() == null) {
			renderFail("该用户没有支付密码，请联系管理员。");
			return;
		}
		if(user.getPayPassword().equalsIgnoreCase(ZOMD5.codeFor(oldPassword))){
			user.setPayPassword(ZOMD5.codeFor(newPassword));
			user.update();
			renderSuccess("修改支付密码成功.");
		}else{
			renderFail("旧支付密码错误.");
		}
	}
}
